package leetcode_201_300;

import java.util.Arrays;

public class LeeCode_283 {
    public static void main(String[] args) {
        moveZeroes(new int[]{0,1,0,3,12});
        moveZeroes(new int[]{0});
    }
    private static void moveZeroes(int[] nums) {
        int n = nums.length;
        int index = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] != 0){
                nums[index] = nums[i];
                index++;
            }
        }
        for (int i = index; i < n; i++) {
            nums[i] = 0;
        }
      /*  int index = n - 1;
        for (int i = n - 1; i >= 0; i--){
            if (nums[i] == 0){
                if (i == index){
                    index--;
                }else {
                    for (int j = i; j < index; j++) {
                        int tmp = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = tmp;
                    }
                    index--;
                }
            }
        }*/
        System.out.println(Arrays.toString(nums));
    }
}
